import { createApp, createVNode, render } from 'vue'
import { createPinia } from 'pinia'
import ElementUI from 'element-plus'
import App from './App.vue'
import router from './router'

import './assets/main.css'
import 'element-plus/dist/index.css'

import LoadingBar from './components/LoadingBar/LoadingBar.vue'
const Vnode = createVNode(LoadingBar)
render(Vnode, document.body)
  console.log(Vnode);
  


const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(ElementUI)
const whiteLis = ['/','/home','/login']  //白名单
router.beforeEach((to, form, next) => {
  console.log("to", to, "from", form);
  // console.log(localStorage.getItem('user'));
  Vnode.component?.exposed?.startLoading()
  if (whiteLis.includes(to.fullPath) || localStorage.getItem('user')!=null) {
    next()
  } else {
    next('/login')
    window.alert('Please login firstly')
  }
})

router.afterEach((to, from) => {
  Vnode.component?.exposed?.endLoading()
  document.title = to.meta.title as string
})

app.mount('#app')
